package com.example.jiaju.utils;

import android.graphics.Rect;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

/**
 * @author starr
 * 用于设置Item之间的间距
 */
public class MyItemDecoration extends RecyclerView.ItemDecoration{
    /**
     * 默认值
     */
    private final int space;
    public MyItemDecoration(int space){
        this.space =space;
    }
    @Override
    public void getItemOffsets(Rect outRect, @NonNull View view,
                               RecyclerView parent, @NonNull RecyclerView.State state) {
        outRect.left = space;
        outRect.right = space;
        outRect.bottom = space;
        // Add top margin only for the first item to avoid double space between items
        if (parent.getChildAdapterPosition(view) == 0) {
            outRect.top = space;
        }
    }
}